package Views.TableModels;

import Models.*;
import byggemarked.Tools;
import javax.swing.table.*;
import java.util.ArrayList;

/**
 * @author Erik
 */
public class RentalTableModel extends DefaultTableModel
{
    private ArrayList<Rental> rentals;
    
    public RentalTableModel()
	{
		this.rentals = new ArrayList<Rental>();
	}
    
    public RentalTableModel(ArrayList<Rental> rentals)
	{
		this.rentals = rentals;
	}
    
    @Override
	public boolean isCellEditable(int row, int column)
	{
		return false;
	}
    
    public void setData(ArrayList<Rental> rentals)
	{
		this.rentals = rentals;
		fireTableDataChanged();
	}
    
    public ArrayList<Rental> getData()
	{
		return this.rentals;
	}
    
    @Override
	public int getColumnCount() {
		return 3;
	}
    
    @Override
	public int getRowCount()
	{
		if(this.rentals == null)
		{
			return 0;
		}
		else
		{
			return this.rentals.size();
		}
	}
    
    @Override
	public String getColumnName(int column) {
		String columnName = "";
		switch(column)
		{
			case 0:
				columnName = "ID";
				break;
			case 1:
				columnName = "Kunde";
				break;
			case 2:
				columnName = "Maskine";
				break;

		}
		return columnName;
	}
    
    @Override
	public Object getValueAt(int row, int column)
	{
		Object value = null;
		switch(column)
		{
			case 0:
				value = this.rentals.get(row).getId();
				break;
			case 1:
				value = Tools.getNameOrCompanyName(this.rentals.get(row).getCustomer());
				break;
			case 2:
				value = this.rentals.get(row).getMachine().getName();
				break;
		}

        return value;
    }
}